package com.fjp.heartguard.app

import androidx.databinding.ObservableField
import com.fjp.heartguard.R
import com.fjp.heartguard.app.data.bean.AccountState
import com.fjp.heartguard.app.data.bean.UserInfo
import com.fjp.heartguard.app.event.AppViewModel
import com.fjp.heartguard.app.event.EventViewModel
import com.fjp.heartguard.app.util.SettingUtil
import com.github.gzuliyujiang.dialog.DialogColor
import com.github.gzuliyujiang.dialog.DialogConfig
import com.github.gzuliyujiang.dialog.DialogStyle
import com.lxj.xpopup.XPopup
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.mmkv.BuildConfig
import com.tencent.mmkv.MMKV
import com.zlw.main.recorderlib.RecordManager
import com.zlw.main.recorderlib.recorder.RecordConfig
import me.hgj.jetpackmvvm.base.BaseApp
import me.hgj.jetpackmvvm.ext.util.jetpackMvvmLog
import java.io.File


//Application全局的ViewModel，里面存放了一些账户信息，基本配置信息等
val appViewModel: AppViewModel by lazy { App.appViewModelInstance }

//Application全局的ViewModel，用于发送全局通知操作
val eventViewModel: EventViewModel by lazy { App.eventViewModelInstance }

class App : BaseApp() {

    companion object {
        lateinit var instance: App
        lateinit var eventViewModelInstance: EventViewModel
        lateinit var appViewModelInstance: AppViewModel
        var userInfo = UserInfo("", 0, "", "1970-01-01", "", "", 0, arrayListOf(), "", "", 0, 0, 0, 0, 0, "", "", "", "", "", "", "", "", 0, 0, "")
        var accountState = AccountState(0,0,1,0)
        var reportSpanIndex1 = 0
        var reportSpanIndex2 = 0
        var reportSpanIndex3 = 0
        var newVersionClickLater = false
        var apkFile: File? = null


    }

    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this.filesDir.absolutePath + "/mmkv")
        instance = this
        eventViewModelInstance = getAppViewModelProvider().get(EventViewModel::class.java)
        appViewModelInstance = getAppViewModelProvider().get(AppViewModel::class.java)
        XPopup.setPrimaryColor(getResources().getColor(R.color.colorAccent))
        DialogConfig.setDialogStyle(DialogStyle.Default)
        DialogConfig.setDialogColor(DialogColor().cancelTextColor(resources.getColor(R.color.colorAccent)).okTextColor(resources.getColor(R.color.colorAccent)))
        RecordManager.getInstance().init(this, false)
        RecordManager.getInstance().changeFormat(RecordConfig.RecordFormat.MP3)
        RecordManager.getInstance().setSource(RecordConfig.SOURCE_MIC) // 麦克风
        RecordManager.getInstance().changeRecordDir(cacheDir.path)
        // 初始化Bugly
        CrashReport.initCrashReport(applicationContext, "1d7b212f02", false)
        jetpackMvvmLog = BuildConfig.DEBUG
        SettingUtil.setListMode(0)


    }

}
